Don't run doc tests if there's a filter
authorAlex Crichton <alex@alexcrichton.com>
Tue, 7 Apr 2015 23:56:45 +0000 (16:56 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Tue, 7 Apr 2015 23:56:45 +0000 (16:56 -0700)
src/cargo/ops/cargo_test.rs
tests/test_cargo_test.rs

index a5993284e0d2d91da8d92678ff196b49f2a862a6..bc2efd22c20fd92147d53f7739375949f625d23e 100644 (file)
@@ -20,7 +20,14 @@ pub fn run_tests(manifest_path: &Path,
         Err(e) => return Ok(Some(e)),
     };
 
-    if options.no_run { return Ok(None) }
+    // If a specific test was requested or we're not running any tests at all,
+    // don't run any doc tests.
+    if let ops::CompileFilter::Only { .. } = options.compile_opts.filter {
+        return Ok(None)
+    }
+    if options.no_run {
+        return Ok(None)
+    }
 
     let libs = compile.package.targets().iter()
                       .filter(|t| t.doctested())
index c237896c12e79be29306872735b2bcfe7d69af45..d57c068297826c55a1dfb6e836d0193c501aed13 100644 (file)
@@ -1445,3 +1445,31 @@ test!(doctest_dev_dep {
     assert_that(p.cargo_process("test").arg("-v"),
                 execs().with_status(0));
 });
+
+test!(filter_no_doc_tests {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [package]
+            name = "foo"
+            version = "0.0.1"
+            authors = []
+        "#)
+        .file("src/lib.rs", r#"
+            /// ```
+            /// extern crate b;
+            /// ```
+            pub fn foo() {}
+        "#)
+        .file("tests/foo.rs", "");
+
+    assert_that(p.cargo_process("test").arg("--test=foo"),
+                execs().with_stdout(format!("\
+{compiling} foo v0.0.1 ([..])
+{running} target[..]debug[..]foo[..]
+
+running 0 tests
+
+test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
+
+", compiling = COMPILING, running = RUNNING)));
+});